/*
 * Copyright (c) 2008 Benoit Bouchez, Nicolas Giard
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package com.noocodecommit.wicket.stuff.jquery.plugin.lightbox;

import com.noocodecommit.wicket.stuff.jquery.plugin.JQPlugin;

/**
 * 
 * @author Nicolas Giard
 */
public class JQLightboxLinkUtils
{

	/**
	 * @param id
	 * @param href
	 * @param classAttr
	 * @param label
	 * @param key
	 * @return JQLightboxLinkBuilder
	 */
	public static JQLightboxLinkBuilder createLink(String id, String href, String classAttr, String label, String key)
	{
		return new JQLightboxLinkBuilder(new JQLightboxLink(id, href, classAttr, label, (key == null ? JQLightboxPlugin.DEFAULT_KEY : key)));
	}

	/**
	 * @param id
	 * @param href
	 * @param classAttr
	 * @return JQLightboxLinkBuilder
	 */
	public static JQLightboxLinkBuilder createLink(String id, String href, String classAttr)
	{
		return new JQLightboxLinkBuilder(new JQLightboxLink(id, href, classAttr, null, null));
	}

	/**
	 * @author Nicolas Giard
	 */
	public static final class JQLightboxLinkBuilder
	{
		private JQLightboxLink link;

		private JQLightboxOptions options;

		/**
		 * @param link
		 */
		public JQLightboxLinkBuilder(JQLightboxLink link)
		{
			this.link = link;
			this.options = new JQLightboxOptions();
		}

		/**
		 * 
		 * @param initMode
		 * @return JQLightboxLinkBuilder
		 */
		public JQLightboxLinkBuilder initMode(int initMode)
		{
			link.getPlugin().setInitMode(initMode);
			return this;
		};

		/**
		 * 
		 * @param initOnceSelector
		 * @return JQLightboxLinkBuilder
		 */
		public JQLightboxLinkBuilder initOnceSelector(String initOnceSelector)
		{
			link.getPlugin().setInitOnceSelector(initOnceSelector);
			return this;
		};

		/**
		 * 
		 * @param overlayOpacity
		 * @return JQLightboxLinkBuilder
		 */
		public JQLightboxLinkBuilder overlayOpacity(double overlayOpacity)
		{
			options.setOverlayOpacity(overlayOpacity);
			return this;
		}

		/**
		 * 
		 * @param borderSize
		 * @return JQLightboxLinkBuilder
		 */
		public JQLightboxLinkBuilder borderSize(int borderSize)
		{
			options.setBorderSize(borderSize);
			return this;
		}

		/**
		 * 
		 * @param inprogress
		 * @return JQLightboxLinkBuilder
		 */
		public JQLightboxLinkBuilder inprogress(boolean inprogress)
		{
			options.setInprogress(inprogress);
			return this;
		}

		/**
		 * 
		 * @param resizeSpeed
		 * @return JQLightboxLinkBuilder
		 */
		public JQLightboxLinkBuilder resizeSpeed(int resizeSpeed)
		{
			options.setResizeSpeed(resizeSpeed);
			return this;
		}

		/**
		 * 
		 * @param widthCurrent
		 * @return JQLightboxLinkBuilder
		 */
		public JQLightboxLinkBuilder widthCurrent(int widthCurrent)
		{
			options.setWidthCurrent(widthCurrent);
			return this;
		}

		/**
		 * 
		 * @param heightCurrent
		 * @return JQLightboxLinkBuilder
		 */
		public JQLightboxLinkBuilder heightCurrent(int heightCurrent)
		{
			options.setHeightCurrent(heightCurrent);
			return this;
		}

		/**
		 * 
		 * @param scale
		 * @return JQLightboxLinkBuilder
		 */
		public JQLightboxLinkBuilder xScale(int scale)
		{
			options.setXScale(scale);
			return this;
		}

		/**
		 * 
		 * @param scale
		 * @return JQLightboxLinkBuilder
		 */
		public JQLightboxLinkBuilder yScale(int scale)
		{
			options.setYScale(scale);
			return this;
		}

		/**
		 * 
		 * @param displayTitle
		 * @return JQLightboxLinkBuilder
		 */
		public JQLightboxLinkBuilder displayTitle(boolean displayTitle)
		{
			options.setDisplayTitle(displayTitle);
			return this;
		}

		/**
		 * 
		 * @param navbarOnTop
		 * @return JQLightboxLinkBuilder
		 */
		public JQLightboxLinkBuilder navbarOnTop(boolean navbarOnTop)
		{
			options.setNavbarOnTop(navbarOnTop);
			return this;
		}

		/**
		 * 
		 * @param slideNavBar
		 * @return JQLightboxLinkBuilder
		 */
		public JQLightboxLinkBuilder slideNavBar(boolean slideNavBar)
		{
			options.setSlideNavBar(slideNavBar);
			return this;
		}

		/**
		 * 
		 * @param navBarSlideSpeed
		 * @return JQLightboxLinkBuilder
		 */
		public JQLightboxLinkBuilder navBarSlideSpeed(int navBarSlideSpeed)
		{
			options.setNavBarSlideSpeed(navBarSlideSpeed);
			return this;
		}

		/**
		 * 
		 * @param displayHelp
		 * @return JQLightboxLinkBuilder
		 */
		public JQLightboxLinkBuilder displayHelp(boolean displayHelp)
		{
			options.setDisplayHelp(displayHelp);
			return this;
		}

		/**
		 * @return JQLightboxLinkBuilder
		 */
		public JQLightboxLink build()
		{
			if (link.getPlugin().getInitMode() == JQPlugin.PLUGIN_INIT_ONCE)
				link.getPlugin().setOptions(options);
			else
				link.setOptions(options);
			return link;
		}
	}
}